import ir.CellDef;

import java.io.File;
import java.io.FileInputStream;

import run.Cell;

import antlr.DumpASTVisitor;
import antlr.collections.AST;
public class TestGrammar {
	
	private static final boolean STDIN_USING = false;
	
	public static void main(String[] args) throws Exception {
		SwarmLexer lexer;
		
		/* Lex */
		if (STDIN_USING)
			 lexer = new SwarmLexer(System.in);
		else {
			FileInputStream swarmProgram = new FileInputStream(new File(args[0]));
			lexer = new SwarmLexer(swarmProgram);
		}

		/* Parse */
		SwarmParser parser = new SwarmParser(lexer);
		parser.expr();
		
		System.out.println("Parsed");
		/* Walk AST */
		AST ast = (AST)parser.getAST();
		DumpASTVisitor visitor = new DumpASTVisitor();
		visitor.visit(ast);
		SwarmWalker walker = new SwarmWalker();
		
		CellDef mainCellDef = walker.file(ast);
		
		Cell realizedMain = mainCellDef.realize();
		realizedMain.exec();
		realizedMain.toString();
	}
}
